#include "modelcolorpalette.h"
#include "ui_modelcolorpalette.h"

ModelColorPalette::ModelColorPalette(QWidget *parent)
    : QColorDialog(parent)
    , ui(new Ui::ModelColorPalette)
{
    ui->setupUi(this);
    initUI();
}

void ModelColorPalette::openColorDialog()
{
    show();
}

ModelColorPalette::~ModelColorPalette()
{
    delete ui;
}

void ModelColorPalette::initUI()
{
    setWindowTitle("模型调色板");
    setOption(QColorDialog::DontUseNativeDialog); // 关键设置

    QList<QPushButton*> buttons = findChildren<QPushButton*>();
    for (QPushButton *btn : buttons) {
        if (btn->text().toLower().contains("ok")) {
            btn->setText("选择");
        } else if (btn->text().toLower().contains("cancel")) {
            btn->setText("关闭");
        }
    }
    connect(this, &QColorDialog::colorSelected, this, [this](const QColor &color) {
        emit colorConfirmed(QVector3D(color.redF(), color.greenF(), color.blueF()));
    });
    connect(this, &QColorDialog::rejected, this, [this]() {
        hide();
    });
}
